﻿using Castle.Core.Configuration;
using MathNet.Numerics.Statistics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Qiniu.Storage;
using Qiniu.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using VOL.Core.Configuration;
using VOL.Core.Utilities;
using VOL.Entity.AttributeManager;
using VOL.Entity.DomainModels.HealthEducation;
using VOL.SmartMecial.IServices.HealthEducation;

namespace VOL.WebApi.Controllers.SmartMecial
{
    /// <summary>
    /// 广播内容控制器
    /// 负责处理广播内容相关的API请求
    /// </summary>
    [Route("api/BroadCastController")]
    [PermissionTable(Name = "BroadCastController")]
    public class BroadCastController : ControllerBase
    {
        private readonly IBroadCastService _service;
        private readonly IConfiguration _configuration;

        public BroadCastController(IBroadCastService service, IConfiguration configuration)
        {
            _service = service;
            _configuration = configuration;
        }


        /// <summary>
        /// 获取所有广播内容
        /// </summary>
        /// <returns>广播内容列表</returns>
        [HttpGet("GetBroadCasts")]
        public async Task<ActionResult<List<BroadCastModel>>> GetBroadCasts()
        {
            return await _service.GetBroadCastModels();
        }

        /// <summary>
        /// 添加广播内容
        /// </summary>
        /// <param name="model">广播内容模型</param>
        /// <returns>添加结果</returns>
        [HttpPost("AddBroadCast")]
        public async Task<ActionResult<int>> AddBroadCast([FromBody] BroadCastModel model)
        {
            if (model == null)
                return BadRequest("广播内容不能为空");

            var result = await _service.AddBroadCast(model);
            return Ok(result);
        }

        /// <summary>
        /// 更新广播内容
        /// </summary>
        /// <param name="model">广播内容模型</param>
        /// <returns>更新结果</returns>
        [HttpPut("UpdateBroadCast")]
        public async Task<ActionResult<int>> UpdateBroadCast([FromBody] BroadCastModel model)
        {
            if (model == null)
                return BadRequest("广播内容不能为空");

            var result = await _service.UpdateBroadCast(model);
            return Ok(result);
        }

        /// <summary>
        /// 删除广播内容
        /// </summary>
        /// <param name="id">广播ID</param>
        /// <returns>删除结果</returns>
        [HttpGet("DeleteBroadCast")]
        public async Task<ActionResult<int>> DeleteBroadCast([FromQuery] int id)
        {
            return await _service.DeleteBroadCast(id);
        }

    }
}

